home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / boxes / demo2 / inistuff.bas < prev    next >
Encoding:
BASIC Source File  |  1995-03-30  |  1.7 KB  |  49 lines

  1. 'INISTUFF.BAS Version 1.7 Date: 03/26/95
  2. 'Steven Gotz
  3. 'Compuserve: 70563,207
  4. 'America On-Line: StevenG400
  5.  
  6. 'This demo does not write to a file yet,
  7. 'but I always use the same file for all my apps
  8. 'so I left in WritePrivateProfileString.
  9.  
  10. 'I let the user use Notepad to modify the INI file but may
  11. 'change that as I add to the demo.
  12.  
  13. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal Appname As String, ByVal KeyName As String, ByVal NewString As String, ByVal FileName As String) As Integer
  14. Declare Function GetPrivateProfilestring Lib "Kernel" (ByVal Appname As String, ByVal KeyName As String, ByVal default As String, ByVal ReturnedString As String, ByVal MAXSIZE As Integer, ByVal FileName As String) As Integer
  15. Global IniName As String
  16.  
  17. 'Function Name: ReadINIFile
  18. '
  19. 'Returns a string from an INI file. To use, call the
  20. 'function and pass it the AppName, KeyName and INI
  21. 'File Name, [Thing$=ReadINIFile(App1,Key1,INIFile)].
  22. 'If you need the returned value to be a integer then
  23. 'use the val command.
  24. '
  25. Function ReadINIFile (Appname, KeyName, FileName As String) As String
  26.  
  27.     Thing$ = String(255, Chr(0))
  28.  
  29.     ReadINIFile = Left(Thing$, GetPrivateProfilestring(Appname, ByVal KeyName, "", Thing$, Len(Thing$), FileName))
  30.  
  31. End Function
  32.  
  33. 'Function Name: WriteINIFile
  34. '
  35. '
  36. 'Writes a string to an INI file. To use, call the
  37. 'function and pass it the sAppname, sKeyName, the New
  38. 'String and the INI File Name.
  39. '[R=WriteINIFile(App1,Key1,NewString,INIFile)].
  40. 'Returns a 1 if  no errors and a 0 if errors.
  41. '
  42. Sub WriteINIFile (Appname, KeyName, NewString, FileName As String)
  43. Dim R As Integer
  44.     
  45.     R = WritePrivateProfileString(Appname, KeyName, NewString, FileName)
  46.  
  47. End Sub
  48.  
  49.